import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.JFrame;


public class screen extends JFrame implements Runnable,MouseMotionListener,MouseListener {
	
	public screen(){
		Toolkit toolkit = Toolkit.getDefaultToolkit();
		Dimension dim = toolkit.getScreenSize();
		addMouseMotionListener((MouseMotionListener)this);
		addMouseListener((MouseListener)this);
		int screenX = dim.width/2;
		int screenY = dim.width/2;
		setSize(screenX,screenY);
		setVisible(true);
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
	}
	public void paint (Graphics g){
		Variable.dbImage = createImage(getWidth(), getHeight());
		Variable.dbg = Variable.dbImage.getGraphics();
		paintComponent(Variable.dbg);
		g.drawImage(Variable.dbImage, 0, 0, this);
	}
	public void paintComponent(Graphics g){
		DrawGraphics.paintScreen(g);
		g.drawRect(Variable.MouseX*32, Variable.MouseY*32, 32, 32);
	}
	public static void main(String[] args) {
		screen a1 = new screen();
		GetImage a2 = new GetImage();
		Thread t1 = new Thread(a1);
		t1.start();
		

	}
	@Override
	public void run() {
		while(true){
			try {
				Thread.sleep(500);
				repaint();
				CheckLevel.check();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}
	@Override
	public void mouseDragged(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mouseMoved(MouseEvent e) {
		Variable.MouseX = e.getX()/32;
		Variable.MouseY = e.getY()/32;
	}
	@Override
	public void mouseClicked(MouseEvent arg0) {
		ChangeTile.setTile(Variable.MouseX,Variable.MouseY);		
	}
	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
}
